package com.acwing.partition18;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/2/5 19:17
 */
public class AC1750救生员 {

    private static final int N = 110;
    private static int[][] intervals = new int[N][2];
    private static int n = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        for (int i = 0; i < n; i++) {
            String[] ss = reader.readLine().split(" ");
            intervals[i] = new int[]{Integer.parseInt(ss[0]), Integer.parseInt(ss[1])};
        }
        int ans = 0;
        Arrays.sort(intervals, 0, n, (o1, o2) -> Integer.compare(o1[0], o2[0]));
        for (int i = 0; i < n; i++) {
            int sum = 0, left = -1, right = -1;
            for (int j = 0; j < n; j++) {
                if (j != i) {
                    if (intervals[j][0] <= right) {
                        right = Math.max(right, intervals[j][1]);
                    } else {
                        sum += right - left;
                        left = intervals[j][0];
                        right = intervals[j][1];
                    }
                }
            }
            sum += right - left;
            ans = Math.max(ans, sum);
        }
        writer.write(ans + "\n");
        writer.flush();
    }
}
